package net.oschina.git.hikoyan.helloapi.controller;

import com.wordnik.swagger.annotations.Api;
import net.oschina.git.hikoyan.helloapi.processor.asyncservlet.AsyncTaskService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;

/**
 * Created by yan on 17/2/8.
 */
@RestController
@Api(value = "async-api", description = "异步servlet")
@RequestMapping("/async")
public class AsyncController {

    private AsyncTaskService asyncCallService = new AsyncTaskService();

    @RequestMapping(value = "/asynctask", method = RequestMethod.GET)
    public DeferredResult<String> asyncTask() {
        final DeferredResult<String> deferredResult = new DeferredResult<String>();
        System.out.println("/asynctask 调用！thread id is : " + Thread.currentThread().getId());
//        asyncCallService.makeRemoteCall(new AsyncTaskCallback() {
//            public void callback(Object result) {
//                System.out.println("异步调用执行完成, thread id is : " + Thread.currentThread().getId());
//
//                deferredResult.setResult("111111");
//            }
//        });
        return deferredResult;
    }
}
